<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Wxuser;
use Illuminate\Http\Request;

class WxuserController extends Controller
{

    public function index(Request $request)
    {

        $nickName = $request->nickName;
        $name = $request->name;
        $mobile = $request->mobile;
        $wxusers = Wxuser::when($name, function ($query) use ($name, $nickName, $mobile) {
            $query->where('name', 'like', '%'.$name."%");
        })
            ->when($mobile, function ($query) use ($mobile) {
                $query->where('mobile', 'like', '%'.$mobile."%");
            })
            ->when($nickName, function ($query) use ($nickName) {
                $query->where('nickName', 'like', '%'.$nickName."%");
            })
            ->orderByDesc('id')->paginate(10);
        return $wxusers;
    }


    public function destroy(Wxuser $wxuser)
    {
        $wxuser->delete();
        return $this->message("删除成功");
    }

}
